//Shkolnij Rostislav
package CalculationCore;

public class CProgramRecord {
	private int iOperationID = -1; 	//operation from 0x00 - 0xff
	private CButtonEntry OperationInfo; //reference to immutable entry in button table
	private int iAddress = -1; 		//operation from 0x00 - 0xff
	private boolean isAddressMode; 	
	
	public CProgramRecord(int numb, boolean addrMode)
	{
		setProgramRecord(numb, addrMode);
	}
	public CProgramRecord(int operID, CButtonEntry info)
	{
		setProgramRecord(operID, info);
	}
	public void setProgramRecord(int numb, boolean addrMode)
	{
		isAddressMode = addrMode;
		if(isAddressMode){
			setiAddress(numb);
		} else {
			setOperationID(numb);
			setOperationInfo(CButtonMiniDB.findBtnEntryByID(numb)); 
		}
	}
	public void setProgramRecord(int operID, CButtonEntry info)
	{
		isAddressMode = false;
		setOperationID(operID);
		setOperationInfo(info); 
	}
	
	// getter & setter---------------------
	public int getOperationID() {
		return iOperationID;
	}

	public void setOperationID(int operID) {
		iOperationID = operID;
	}

	public CButtonEntry getOperationInfo() {
		return OperationInfo;
	}

	private void setOperationInfo(CButtonEntry operationInfo) {
		OperationInfo = operationInfo;
	}


	public int getiAddress() {
		return iAddress;
	}

	public void setiAddress(int iAddress) {
		this.iAddress = iAddress;
	}
	public boolean isAddressMode() {
		return isAddressMode;
	}
	public String toString(int len) {
		if(isAddressMode){
			return String.format(" _%0"+len+"d_ ", iAddress);
		} else {
			if(OperationInfo.getsBtnComp() == "")
				return String.format(" 0x%02X \t [%s] \t\t \"%s\" \"%s\"", 
						iOperationID, 
						OperationInfo.getsBtnSign(),
						OperationInfo.getsBtnType(),
						OperationInfo.getsBtnName());
			else
				return String.format(" 0x%02X \t [%s] + [%s] \t \"%s\" \"%s\"", 
						iOperationID, 
						OperationInfo.getsBtnComp(),
						OperationInfo.getsBtnSign(),
						OperationInfo.getsBtnType(),
						OperationInfo.getsBtnName());
		}

	}
}
